from utils.utils import *
import allure
from faker import Faker
faker = Faker(locale='zh_cn')
name = faker.name()
@allure.story("新增用户分组")
def test_group():
    #==============新增用户分组========
    # 登录，获取token
    reset_token()
    # 发起新增用户分组
    add_user_group = send_requests(
        '新增用户分组','post',
        '/adminapi/user/user_group/save.html',
        {'group_name': f'{name}'}
    ).\
        validate(). \
        assert_equal("status_code", 200).\
        assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
        assert_equal("body.status", 200).\
        assert_equal("body.msg", "提交成功").\
        assert_equal("body.code", "100017")
    # 添加step
    add_user_group_step = step_obj(add_user_group)
    # 执行获取返回值
    res = get_last_response([add_user_group_step,])
    
@allure.story("删除用户分组")
def test_delGroup():
    # 登录，获取token
    reset_token()
    # ======= 查询用户分组==============
    get_user_group = send_requests('查询用户分组','get','/adminapi/user/user_group/list?page=1&limit=15').\
        validate().\
        assert_equal("status_code", 200).\
        assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
        assert_equal("body.status", 200).\
        assert_equal("body.msg", "success")
    get_user_group_step = step_obj(get_user_group)
    res = get_last_response([get_user_group_step,])
    for i in res['res_body']['data']['list']:
        if i['group_name'] == name:
            id = i['id']
    # =====删除用户分组=====
    delete_user_group = send_requests(
        "删除用户分组",'delete',"/adminapi/user/user_group/del/" + str(id)
    ).\
    validate().\
    assert_equal("status_code", 200).\
    assert_equal('headers."Content-Type"', "application/json; charset=utf-8").\
    assert_equal("body.status", 200).\
    assert_equal("body.msg", "删除成功!")
    delete_user_group_step = step_obj(delete_user_group)
    res = get_last_response([delete_user_group_step,])
